// fenxiao/rechargeMSM/index.js
var app = getApp();
const utils = require('../../utils/pay.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    money: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },

  bindMoney: function(e){
    this.setData({
      money: e.detail.value
    })
  },
  //安卓手机现金直冲
  submitAccountBalanceOrder: function () {
    let money = parseInt(this.data.money)
    if (!this.checkMoney(money)) {
      wx.showModal({
        title: '提示',
        content: '请输入50-9900整数',
        showCancel: false,
      })
      return
    }
    wx.showLoading({
      title: '充值中',
      mask: true
    })
    wx.request({
      url: app.globalData.host + '/api/Order/SubmitAccountBalanceOrder',
      data: {
        uid: app.globalData.userInfo.Uid,
        count: money / 50
      },
      method: 'POST',
      success: function (res) {
        wx.hideLoading();
        if (res.data.Code == 0) {
          utils.wxpay(app, res.data.Data, 1)
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.Message,
            showCancel: false
          })
        }
      }
    })
  },
  //苹果升级申请申请余额代充
  requestAccountBalance: function () {
    wx.showModal({
      title: '提示',
      content: '发送升级申请，保障账户安全！\r\n专属运营经理会在24小时内联系您',
      confirmText: "立即申请",
      success(res) {
        if (res.confirm) {
          wx.showLoading({
            title: '申请中',
            mask: true
          })
          wx.request({
            url: app.globalData.host + '/api/Distributor/RequestAccountBalance?uid=' + app.globalData.userInfo.Uid,
            success: function (res) {
              wx.hideLoading();
              if (res.data.Code == 0) {
                wx.showToast({
                  title: '成功'
                })
              } else {
                wx.showModal({
                  title: '提示',
                  content: res.data.Message,
                  showCancel: false
                })
              }
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  //金额验证
  checkMoney: function (obj) {
    if (!obj) {
      return false;
    } else {
      return typeof obj === 'number' && obj % 50 === 0;//是整数，则返回true，否则返回false
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

})